/****************************************************************************\
*                                                                            *
*  Copyright 2008 The CAnt2 Project (http://code.google.com/p/cant2)         *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
\****************************************************************************/
#ifndef INCLUDED_UNITTEST_H__
#define INCLUDED_UNITTEST_H__

#include <UnitTest++/src/UnitTest++.h>

#define CHECK_NOTHROW(expr)\
    do \
    { \
        try { \
            (void)(expr); \
        } \
        catch (std::exception& e) { \
            testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
                    "Unhandled exception in CHECK_NOTHROW(" #expr ")"); \
            testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
                    e.what()); \
        } \
        catch (...) { \
            testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
                    "Unhandled exception in CHECK_NOTHROW(" #expr ")"); \
        } \
    } while (0)

template< typename Expected, typename Actual >
void CheckNotEqual( UnitTest::TestResults& results, Expected const& not_expected, Actual const& actual, UnitTest::TestDetails const& details)
{
    if (not_expected == actual)
    {
        UnitTest::MemoryOutStream stream;
        stream << "Expected anything except " << not_expected << " but it was " << actual;

        results.OnTestFailure(details, stream.GetText());
    }
}

#define CHECK_NOTEQUAL(not_expected, actual) \
    do \
    { \
        try { \
            CheckNotEqual(testResults_, not_expected, actual, UnitTest::TestDetails(m_details, __LINE__)); \
        } \
        catch (...) { \
            testResults_.OnTestFailure(UnitTest::TestDetails(m_details, __LINE__), \
                    "Unhandled exception in CHECK_NOTEQUAL(" #not_expected ", " #actual ")"); \
        } \
    } while (0)

#endif /* #ifndef INCLUDED_UNITTEST_H__ */

